package com.book.app.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.book.app.entity.Logs;
import com.book.app.service.LogsService;
import com.book.app.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@Api(tags = "日志模块")
@RestController
@RequestMapping("logs")
@CrossOrigin //前后端分离配置跨域访问
public class LogsController  {
    /**
     * 服务对象
     */
    @Resource
    private LogsService logsService;

    @ApiOperation("分页查询日志信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "分页起始数据",required = true,example = "1"),
            @ApiImplicitParam(name = "limit",value = "每页显示分页最大数据",required = true,example = "10"),
            @ApiImplicitParam(name = "opername",value = "操作人姓名查询",example = "张三"),
    })
    @GetMapping("/findPager")
    public CommonResult<Map<String,Object>> findPager(Integer page, Integer limit, String opername){

        QueryWrapper<Logs> queryWrapper=new QueryWrapper<>();
        if(!"".equals(opername)&&opername!=null){
            queryWrapper.like(true,"opername",opername);
        }
        Map<String,Object> map=new HashMap<>();
        map.put("page",page);
        map.put("count",logsService.count(queryWrapper));
        map.put("data",logsService.page(new Page<Logs>(page,limit),queryWrapper).getRecords());

        return CommonResult.success(map);
    }


}

